﻿//----------------------------------------------------------------
// <copyright file="MptConfigurationTest.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//----------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MptCodeLibrary.Configuration;

namespace Test.UnitTest
{
    [TestClass]
    public class MptConfigurationTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void VerifyServerConfigurationSection()
        {
            MptConfiguration mptConfiguration = new MptConfiguration();
            List<TeamServerConfiguration> teamServers = (List<TeamServerConfiguration>)mptConfiguration.TeamServers;

            Assert.AreEqual(2, teamServers.Count, "There should be only 2 servers in the test config");
            Assert.AreEqual("b21eetfs02", teamServers[0].ServerName, "The server name from the config file isn't what is expected");
        }

        [TestMethod]
        public void VerifyProjectNameConfigurationSection()
        {
            MptConfiguration mptConfiguration = new MptConfiguration();
            List<string> projectNames = (List<string>) mptConfiguration.TeamProjects;

            Assert.AreEqual(2, projectNames.Count, "There should have been 2 projects names in the config file");
            Assert.AreEqual("Project1", projectNames[0]);
            Assert.AreEqual("Project2", projectNames[1]);
        }

        [TestMethod]
        public void VerifyLastUpdateDateWillSaveForFirstServer()
        {
            MptConfiguration mptConfiguration = new MptConfiguration();
            string lastUpdateDate = DateTime.Now.ToString();

            List<TeamServerConfiguration> teamServers = (List<TeamServerConfiguration>)mptConfiguration.TeamServers;
            Assert.IsTrue(teamServers.Count > 0, "There should be at least 1 server in the test config to start with");

            teamServers[0].RollupLastUpdated = lastUpdateDate;

            mptConfiguration.TeamServers = teamServers;

            MptConfiguration mptConfiguration2 = new MptConfiguration();
            List<TeamServerConfiguration> updatedTeamServers = (List<TeamServerConfiguration>)mptConfiguration2.TeamServers;
            Assert.IsTrue(updatedTeamServers[0].RollupLastUpdated == lastUpdateDate, "the date for the first server didn't save");
        }
        
        [TestMethod]
        public void VerifyLastUpdateDateWillSaveForSecondServer()
        {
            MptConfiguration mptConfiguration = new MptConfiguration();
            string lastUpdateDate = DateTime.Now.ToString();

            List<TeamServerConfiguration> teamServers = (List<TeamServerConfiguration>)mptConfiguration.TeamServers;
            Assert.IsTrue(teamServers.Count > 1, "There should be at least 2 servers in the test config to start with");
            
            teamServers[1].RollupLastUpdated = lastUpdateDate;

            mptConfiguration.TeamServers = teamServers;

            MptConfiguration mptConfiguration2 = new MptConfiguration();
            List<TeamServerConfiguration> updatedTeamServers = (List<TeamServerConfiguration>)mptConfiguration2.TeamServers;
            Assert.IsTrue(updatedTeamServers[1].RollupLastUpdated == lastUpdateDate, "the date for the second server didn't save");
        }

       
    }
}
